package com.ng.desktop.services;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class NGFactoryBean {

	private static NGFactoryBean instance = null;

	private ApplicationContext applicationContext;

	public static NGFactoryBean getInstance() {

		if (instance == null) {
			instance = new NGFactoryBean();
		}

		return instance;

	}

	private NGFactoryBean() {
		String[] contextPaths = new String[]{"app-context.xml"};
		applicationContext = new ClassPathXmlApplicationContext(contextPaths);
	}

	public <T> T getBean(Class<T> clazz) {

		T bean = (T) applicationContext.getBean(clazz.getCanonicalName());

		return bean;
	}

	public Object getBean(String id) {

		return applicationContext.getBean(id);
	}

	public static void main(String[] args) {

	}
}